<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page, index) in pages" :key="index">
        <div class="icon" v-for="item in page" :key="item.id">
          <div class="icon-img">
            <img class="icon-img-content" :src="item.iconUrl">
          </div>
          <p class="icon-desc">
            {{item.desc}}
          </p>
        </div>
      </swiper-slide>
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>
<script>
export default {
  data () {
    return {
      swiperOption: {
        // 指定哪一个元素容器 作为页面指示页
        pagination: '.swiper-pagination',
        // 让页面原点 有切换页面的功能
        paginationClickable: true
      },
      iconLists: [
        {
          id: '100001',
          iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '景点门票景点门票景点门票景点门票'
        },
        {
          id: '100002',
          iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '一日游'
        },
        {
          id: '100003',
          iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '郑州必游'
        },
        {
          id: '100004',
          iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '夏日玩水'
        },
        {
          id: '100005',
          iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '名胜古迹'
        },
        {
          id: '100006',
          iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '景点门票'
        },
        {
          id: '100007',
          iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '一日游'
        },
        {
          id: '100008',
          iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '郑州必游'
        },
        {
          id: '100009',
          iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '夏日玩水'
        },
        {
          id: '1000010',
          iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
          desc: '名胜古迹'
        }
      ]
    }
  },
  computed: {
    // pages[[],[],[],[]]
    pages () {
      const pages = []
      this.iconLists.forEach((item, index) => {
        // 8
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>
<style lang="stylus" scoped>
@import '~styles/ellipsis.styl'
@import '~styles/varibles.styl'
  .icons >>> .swiper-pagination
    bottom 5px
  .icons >>> .swiper-pagination-bullet-active
    background $bgColor
  .icons
    margin-top .1rem
    .icon
      position relative
      overflow hidden
      float left
      width 25%
      height 0
      padding-bottom 25%
      .icon-img
       position absolute
       top 0
       left 0
       right 0
       bottom .44rem
       box-sizing border-box
       .icon-img-content
        display block
        margin 0 auto
        height 100%
      .icon-desc
        position absolute
        left 0
        right 0
        bottom 0
        height .44rem
        line-height .44rem
        text-align center
        color #000
        ellipsis()
</style>
